-
-
Notifications
You must be signed in to change notification settings - Fork 301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature] Add Task Registry #329
base: master
Are you sure you want to change the base?
Conversation
ef36dce
to
17f032f
Compare
""" | ||
A Registry allows defining a collection of Actors not directly bound to a Broker. | ||
|
||
This allows your code to declar Actors before configuring a Broker. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This allows your code to declar Actors before configuring a Broker. | |
This allows your code to declare actors before configuring a broker. |
from .actor import Actor, _queue_name_re | ||
|
||
|
||
class Registry: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great to see this! I nearly have the same class in my projects.
I have implemented this method as well:
def enqueue(self, message, *, delay=None):
raise RuntimeError(
"ActorCollector has not transferred its actors to an actual broker. "
"Ensure transfer_actors() is called."
)
It ensures that the user is told what is going on when trying to call send() on an actor before doing the bind.
"middleware to your Broker?" | ||
) % (actor_name, invalid_options_list)) | ||
|
||
broker.declar_actor(actor) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my code I have an additional helper method to allow binding multople collectors (here it would be registries) at once.
This is handy when linking up independet code from multiple packages.
def transfer_actors(broker, collectors: List[ActorCollector]):
for ac in collectors:
ac.transfer_actors(broker)
I have been able to achieve something like this by defining a middleware, that effectively looks like:
Then I can reference API_ACTORS from anywhere in my code. Not sure if this approach works. I wanted to optionally store tasks for running via an API. |
Ah, but I have missed the point about doing this separately from a broker. Never mind. |
flask-melodramatiq solves this as well. |
Currently a WIP, this adds a Registry class to allow registering tasks independently of a Broker, and later register them with a given broker.
This solves the chicken-and-egg problem where decorated task functions may be imported before the configuration for the Broker has been loaded and applied.
Still needs tests...